// Ajax 文件下载
jQuery.downloadInterface = function(url, method, data) {

    data = data || {};

    if (url && data) {

        data = typeof data == 'string' ? data : jQuery.param(data);
        var inputs = '';
        jQuery.each(data.split('&'), function() {
            var pair = this.split('=');
            inputs += '<input type="hidden" name="' + pair[0] + '" value="' + decodeURI(pair[1]) + '" />';
        }); // request发送请求

        jQuery('<form action="' + url + '" method="' + (method || 'post') + '">' + inputs + '</form>')
            .appendTo('body').submit().remove();
    };
};

// Ajax 文件上传
jQuery.importInterface = function(url, method) {

    if (url) {

        jQuery("#importInterface").remove();

        var inputs = '<input type="file" name="file" class="importClick" hidden/>';

        jQuery('<form id="importInterface" action="' + url + '" method="' + (method || 'post') + '" enctype="multipart/form-data">' + inputs + '</form>')
            .appendTo('body');
        jQuery(".importClick").trigger("click");
        jQuery(".importClick").on("change", function() {
            $("form#importInterface").ajaxSubmit({
                // type: "get",
                // url: $.getRadParamUrl(jsons("CSM_IMPORT")),
                success: function(data) {

                    if (data.status.code == 200) {
                        _as.jAlert("<p>批量导入成功！</p>", function() {
                            location.reload();
                        });
                    } else {
                        _as.jAlert("<p>批量导入失败！</p><p>" + data.status.message + "</p>");
                    }
                },
                error: function(msg) {
                    _as.jAlert("<p>批量导入失败！</p><p>" + msg + "</p>");
                }
            });
        })
    };
};